package com.nttdata.ocr.controller;

import com.nttdata.ocr.domain.dto.TextAccuracyLocationDto;
import com.nttdata.ocr.domain.dto.TextOcrDto;
import com.nttdata.ocr.domain.param.OcrParam;
import com.nttdata.ocr.response.ResponseResult;
import com.nttdata.ocr.service.OcrService;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * OCR 文本识别接口
 */
@RestController
@RequestMapping("/text")
//@Validated
public class OcrTextController {

    @Autowired
    private OcrService ocrService;

    @PostMapping("/text-only")
    public ResponseResult<List<String>> textOnly(@RequestBody @Valid OcrParam ocrParam) {
        List<String> textList = ocrService.ocrText(ocrParam.getImgBase64(), ocrParam.getImgType());
        return ResponseResult.success(textList);
    }

//    @GetMapping("/text-only2")
//    public ResponseResult<List<TextOcrDto>> textOnly(@RequestParam @NotBlank String imgBase64, @RequestParam @NotBlank String imgType) {
//        List<TextOcrDto> textOcrDtoList = ocrService.ocrText(imgBase64, imgType);
//        return ResponseResult.success(textOcrDtoList);
//    }

    @PostMapping("/text-location-accuracy")
    public ResponseResult<List<TextAccuracyLocationDto>> textLocationAccuracy(@RequestBody @Valid OcrParam ocrParam) {
        List<TextAccuracyLocationDto> ocrList = ocrService.ocrTextAccuracyLocation(
                ocrParam.getImgBase64(),
                ocrParam.getImgType()
        );
        return ResponseResult.success(ocrList);
    }
}
